package com.lu.controller;

import com.lu.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller//将userDemo交由spring创建bean
//@ResponseBody//将引用数据类型对象转换成json字符串
public class UserDemo {

    @RequestMapping("/find1")//设置访问当前方法的映射路径
    //@RequestBody 将请求体json字符串转换成引用数据类型对象,用于post请求,get没有请求体
    public User find1(@RequestBody User user){
        System.out.println("find1执行了");
        System.out.println(user);
        return user;
    }

    @RequestMapping("/find2")
    public String find2(){
        System.out.println("4");
        int i = 1/0;
        return "/success.jsp";
    }

    @RequestMapping("/find3")
    @ResponseBody
    public String find3(User user, HttpSession session){
        System.out.println(user.getName()+user.getPassword());
        if (user.getName().equals("lisi") && user.getPassword().equals("1234")) {
            session.setAttribute("name",user.getName());
            System.out.println("find3"+user.getName());
            return "登录成功";
        }
        System.out.println("登录失败");
        return "登录失败请重新登录";
    }
}
